package qldc.pm.tiensu.service.impl;

import java.util.Date;
import java.util.List;

import qldc.pm.tiensu.NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException;
import qldc.pm.tiensu.model.PhieuThongTinVeNguoiCoTienSu;
import qldc.pm.tiensu.model.TEMP_PhieuThongTinVeNguoiCoTienSu;
import qldc.pm.tiensu.model.TEMP_TienSu;
import qldc.pm.tiensu.model.impl.TEMP_PhieuThongTinVeNguoiCoTienSuImpl;
import qldc.pm.tiensu.service.TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceUtil;
import qldc.pm.tiensu.service.base.TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceBaseImpl;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.Validator;

/**
 * The implementation of the t e m p_ phieu thong tin ve nguoi co tien su local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.tiensu.service.TEMP_PhieuThongTinVeNguoiCoTienSuLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.tiensu.service.base.TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceBaseImpl
 * @see qldc.pm.tiensu.service.TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceUtil
 */
public class TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceImpl
    extends TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceBaseImpl {
	public TEMP_PhieuThongTinVeNguoiCoTienSu addTEMPPhieu(long tienSuId, long userId, String userName,
			String maSoHoSoTienSuTuToaAn, String nguoiTrichLuc,
			String thamPhan,
			String soDinhDanhCaNhan, String chuThich, 
			String noiTamTruDiaChi,
			String hoTenVoHoacChong,
			String hoTenCha,
			String hoTenMe, String noiThuongTruDiaChi)
			throws SystemException {
		long PhieuThongTinVeNguoiCoTienSuId = counterLocalService.increment(TEMP_PhieuThongTinVeNguoiCoTienSu.class.getName());
		TEMP_PhieuThongTinVeNguoiCoTienSu phieuThongTin = createTEMP_PhieuThongTinVeNguoiCoTienSu(PhieuThongTinVeNguoiCoTienSuId);
		
		phieuThongTin.setUserId(userId);
		phieuThongTin.setUserName(userName);
		phieuThongTin.setCreateDate(new Date());
		phieuThongTin.setNoiTamTruDiaChi(noiTamTruDiaChi);
		phieuThongTin.setHoTenCha(hoTenCha);
		phieuThongTin.setHoTenMe(hoTenMe);
		phieuThongTin.setHoTenVoHoacChong(hoTenVoHoacChong);
		phieuThongTin.setTienSuId(tienSuId);
		phieuThongTin.setMaSoHoSoTienSuTuToaAn(maSoHoSoTienSuTuToaAn);
		phieuThongTin.setNguoiTrichLuc(nguoiTrichLuc);
		phieuThongTin.setThamPhan(thamPhan);
		phieuThongTin.setSoDinhDanhCaNhan(soDinhDanhCaNhan);
		phieuThongTin.setChuThich(chuThich);
		phieuThongTin.setNoiThuongTruDiaChi(noiThuongTruDiaChi);

		phieuThongTin = addTEMP_PhieuThongTinVeNguoiCoTienSu(phieuThongTin);

		return phieuThongTin;
	}
	public TEMP_PhieuThongTinVeNguoiCoTienSu findByTienSuId(long tienSuId) {
		TEMP_PhieuThongTinVeNguoiCoTienSu phieuThongTinVeNguoiCoTienSu = null;

		try {
			phieuThongTinVeNguoiCoTienSu = temp_PhieuThongTinVeNguoiCoTienSuPersistence.findByTienSuId(tienSuId);
		} 
		catch (SystemException e) {
		}
		catch (NoSuchTEMP_PhieuThongTinVeNguoiCoTienSuException e) {
			
		}

		return phieuThongTinVeNguoiCoTienSu;
	}
	public void xoaByTienSuId(long tienSuId) {
		TEMP_PhieuThongTinVeNguoiCoTienSu phieuThongTinVeNguoiCoTienSu = findByTienSuId(tienSuId);
		if (Validator.isNotNull(phieuThongTinVeNguoiCoTienSu))
			try {
				TEMP_PhieuThongTinVeNguoiCoTienSuLocalServiceUtil.deleteTEMP_PhieuThongTinVeNguoiCoTienSu(phieuThongTinVeNguoiCoTienSu);
			} catch (SystemException e) {
				System.out.println("Not found");
			}

	}
	public void xoaAllTempPhieuByDoiTuongTienSuId(long doiTuongTienSuId){
		List<TEMP_TienSu> tienSu;
		try {
			tienSu = temp_TienSuPersistence.findByDoiTuongTienSuId(doiTuongTienSuId);
			for (TEMP_TienSu ts : tienSu){
				xoaByTienSuId(ts.getTienSuId());
			}
		} catch (SystemException e) {
			System.out.println("Not found data");
		}
		
	}
}
